package net.uhuijia.goods.goodspu.controller;

import net.uhuijia.appbase.controller.BaseController;
import net.uhuijia.goods.goodsku.persistence.model.GoodSku;
import net.uhuijia.goods.goodsku.service.GoodSkuService;
import net.uhuijia.goods.goodspu.persistence.model.GoodSpu;
import net.uhuijia.goods.goodspu.persistence.model.GoodSpuExample;
import net.uhuijia.goods.goodspu.service.GoodSpuService;
import net.uhuijia.vo.good.GoodZBListVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value="/client/goodSpu")
public class GoodSpuClientController  extends BaseController<GoodSpuService, GoodSpu, GoodSpuExample> {

    @Autowired
    private GoodSpuService goodSpuService;
    @Autowired
    private GoodSkuService goodSkuService;

    /**
     * @Author xzj
     * @Description //通过spuId查询商品信息
     * @Date  2018/10/8
     * @Param
     * @return
     **/
    @RequestMapping(value = "/getGoodSpu/{spuId}")
    @ResponseBody
    public GoodSpu getGoodSpuBySpuId(@PathVariable("spuId")String spuId){
        if(StringUtils.isEmpty(spuId))
            throw  new IllegalArgumentException();
        GoodSpu goodSpu = this.goodSpuService.get(spuId);
        return goodSpu;
    }

    /**
     * 将GoodSpu 转换成直播右侧商品列表信息 GoodZBListVo
     * @param spuId
     * @return
     */
    @RequestMapping(value = "/wrapToGoodZBListVo/{spuId}")
    @ResponseBody
    public GoodZBListVo goodSpuWrapToGoodZBListVo(@PathVariable("spuId") String spuId){
        GoodZBListVo goodZBListVo = this.goodSpuService.goodSpuWrapToGoodZBListVo(spuId);
        return goodZBListVo;
    }
    /**
     * @Author xzj
     * @Description //获取商品库存
     * @Date  2018/10/8
     * @Param
     * @return
     **/
    @RequestMapping(value = "/skuInvertory")
    @ResponseBody
    public Integer getGoodSkuInvertory(@RequestParam("spuId") String spuId, @RequestParam("groupPropertyId")String groupPropertyId){
        if(!StringUtils.isNoneBlank(spuId,groupPropertyId))
            throw  new IllegalArgumentException();
        int count = this.goodSkuService.getGoodSkuInvertory(spuId,groupPropertyId);
        return count;
    }
    /**
     * @Author xzj
     * @Description // 检查商品规格库存是否足够
     * @Date  2018/10/8
     * @Param
     * @return
     **/
    @RequestMapping(value = "/checkSkuInvertory")
    @ResponseBody
    public Boolean checkGoodSkuInvertoryIsEnough(@RequestParam("spuId")String spuId, @RequestParam("groupPropertyId")String groupPropertyId,@RequestParam("count")Integer count){
        if(!StringUtils.isNoneBlank(spuId,groupPropertyId) || count==null || count.intValue()==0)
            throw  new IllegalArgumentException();
        boolean flag = this.goodSkuService.checkGoodSkuInvertoryIsEnough(spuId,groupPropertyId,count);
        return flag;
    }
    /**
     * @Author xzj
     * @Description //根据spuId和匹配Id查询商品Sku
     * @Date  2018/10/8
     * @Param
     * @return
     **/
    @RequestMapping(value = "/getGoodSkuBySpuIdAndPropertyId")
    @ResponseBody
    public GoodSku getGoodSkuBySpuIdAndPropertyId(@RequestParam("spuId") String spuId, @RequestParam("groupPropertyId")String groupPropertyId){
        if(!StringUtils.isNoneBlank(spuId,groupPropertyId))
            throw  new IllegalArgumentException();
        GoodSku goodSku = this.goodSkuService.getGoodSkuBySpuIdAndPropertyId(spuId,groupPropertyId);
        return goodSku;
    }
    /**
     * @Author xzj
     * @Description //根据goodSkuId查询商品规格
     * @Date  2018/10/8
     * @Param
     * @return
     **/
    @RequestMapping(value = "/getGoodSkuByGoodSkuId")
    GoodSku getGoodSkuByGoodSkuId(@RequestParam("goodSkuId") String goodSkuId){
        if(StringUtils.isEmpty(goodSkuId))
            throw new  IllegalArgumentException();
        GoodSku goodSku = this.goodSkuService.get(goodSkuId);
        return goodSku;
    }





}
